# -*- coding: UTF-8 -*-

def LoadXMLWithMinidom(xmlfile):
	from xml.dom.minidom import parse
	try:
		dom = parse(xmlfile)
	except Exception:
		print "parse() failed"
	else:
		print "XML load successful!"
		#do something with dom
		items = dom.getElementsByTagName("item")
		for item in items:
			for field in item.childNodes:
				print field.nodeName + ': ' + field.firstChild.nodeValue
		
		dom.unlink()

def LoadXMLWithElementTree(xmlfile):
	import xml.etree.ElementTree
	try:	
		tree = xml.etree.ElementTree.parse(xmlfile)
	except Exception:
		print "parse() failed"
	else:
		print "XML load successful!"
		#do something with tree
		# findall(path) path에 tag를 쓰면 바로 아래의 서브 엘레멘트만
		# 찾기때문에 */tag의 형식으로 써주어야 한다.
		items = tree.findall("*/item")
		for item in items:
			fields = item.getchildren()
			for field in fields:
				print field.tag + ':' + field.text



filename = str( raw_input("xml file name: ") )
try:
	xmlfile = open(filename, "r")
except IOError:
	print "Invalid file name or path"
else:
	LoadXMLWithElementTree(xmlfile)
	#LoadXMLWithMinidom(xmlfile)
